package com.moo.order.service.impl;

import com.moo.order.model.Order;
import com.moo.order.repository.OrderRepository;
import com.moo.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Project Name: moo-order
 * Author: fhw
 * File Name: OrderServiceImpl
 * Package Name: com.moo.order.service.impl
 * Date: 2020/7/25 9:47 下午
 * Copyright (c) 2020,All Rights Reserved.
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderRepository orderRepository;

    @Override
    public List<Order> listOrders() {
        return orderRepository.findAll();
    }

    @Override
    public Order findById(Long id) {
        Optional<Order> order = orderRepository.findById(id);
        if (order.isPresent()) {
            return order.get();
        }
        return null;
    }
}
